import { show_loading, stop_loading } from "./ditto";
import { pathrouter } from "./pathrouter";
import { pregohome } from "./pregohome";
import { resolvemdpathfromurl } from "./resolvemdpathfromurl";
import { states } from "./states";
import { loadprerenderedmarkdown } from "./loadprerenderedmarkdown";
export default async function loadpage() {
    await loadprerenderedmarkdown();
    const { cachemain } = states;
    // const appvm = getappvm();
    // console.log(cachemain);
    // window.scrollTo(0, 0);
    show_loading();
    const path: string = resolvemdpathfromurl();

    const marktext = cachemain.get(path);
    const { cachetoc } = states;
    const toc = cachetoc.get(path);
    const url = path;
    if (marktext && toc) {
        // contenthtml.set(marktext);
        stop_loading();
        // Reflect.set(appvm, "showsrc", true);
        // addmathjaxstyle(path);
        return;
    } else {
        if (!process.env.PRERENDER) {
        } else {
            if (!states.menulist.includes(url)) {
                if (Object.keys(pathrouter.getparams()).length !== 0) {
                    requestAnimationFrame(() => {
                        setTimeout(() => {
                            console.error(
                                "Opps! ... File not found!\n5秒后返回主页"
                            );
                            pregohome();
                        }, 1000);
                    });
                    return;
                }
            }
        }
    }
    stop_loading();
    // } else {
    //     stop_loading();
    //     return;
    // }
}
